package club.justwill.single.Controller;

import club.justwill.single.Service.SkuService;
import club.justwill.single.assembler.SkusAssemble;
import club.justwill.single.bean.SearchSkus;
import club.justwill.single.bean.SkuSupportResp;
import club.justwill.single.model.CoreConstants;
import club.justwill.single.model.JsonResponse;
import club.justwill.single.model.SecurityToken;
import club.justwill.single.persistence.document.SkuSupport;
import club.justwill.single.persistence.jpo.Skus;
import club.justwill.single.persistence.store.SkuSupoortStore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.WebApplicationContext;

import java.util.List;

/**
 * Created by luoyu on 1/1/16.
 */
@RestController
@Scope(WebApplicationContext.SCOPE_SESSION)
public class SkusController extends BaseController{
    public static Logger logger = LoggerFactory.getLogger(SkusController.class);


    @Autowired
    private SkusAssemble skusAssemble;

    @Autowired
    private SkuService skuService;

    @RequestMapping(value = URL_PROJECT_SKUS_SEARCH, method = RequestMethod.POST, produces = CoreConstants.MIME_JSON)
    public JsonResponse searchSkusByProjectId(@PathVariable long projectId){
        JsonResponse obj = new JsonResponse();
        SecurityToken token = new SecurityToken(sessionState.getUserId());
        token.generateToken(sessionState);
        List<Skus> skusList = skuService.searchSkusByProjectId(token,projectId,obj);
        obj.setData(skusAssemble.assembleSkusList(skusList));
        obj.setSuccessful();
        return obj;
    }

    @RequestMapping(value = URL_PROJECT_SKU_SUPPORT_SEARCH, method = RequestMethod.POST, produces = CoreConstants.MIME_JSON)
    public JsonResponse searchSkuSupportByProjectId(@PathVariable long projectId) {
        JsonResponse obj = new JsonResponse();
        List<SkuSupportResp> skuSupportRespList = skuService.searchSkuSupportByProjectId(obj,projectId);
        obj.setData(skuSupportRespList);
        obj.setSuccessful();
        return obj;
    }

}
